﻿using PubSub;
using Syncfusion.Windows.Forms;
using Syncfusion.WinForms.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WinForm.NET4.Sample.CustomControl;
using WinForm.NET4.Sample.Extensions;

namespace WinForm.NET4.Sample
{
    public partial class Shell : SfForm
    {
        string imagepath = "Images\\";

        public Shell()
        {
            InitializeComponent();

            /*You may add a rich text if need NOT a captionBar
            this.Style.TitleBar.AllowRichText = true;
            this.Text = "{\\rtf1\\ansi\\deff0{\\colortbl;\\red255\\green255\\blue255;\\red250\\green0\\blue0;}" + "{\\fonttbl{\\f0 Segoe UI;\r\n}}\\qc\\f0\\fs25 {\\cf1 基础框架代码 - \\cf2 \\b Win Form}}";
            */
            this.CenterToScreen();
            this.MinimumSize = this.Size;

            //Style.Border.Width = 0;
            //Style.Border.Color = Color.Black;
            var captionBar = new CaptionBar();
      
            captionBar.CaptionMouseUp += Bar_CaptionMouseUp;
            this.TitleBarTextControl = captionBar;

            //after assign a control to TitleBarTextControl, the client area in this form will be changed,
            //need force to add a top padding.
            this.Padding = new Padding(0, this.Style.TitleBar.Height + 1, 0, 0);
        }

        private void Bar_CaptionMouseUp(object sender, int index, EventArgs e)
        {
            switch (index)
            {
                case 1:

                    TabContainer.AddPage(index, new ModuleA.MainForm());

                    TabContainer.SelectPage(index);
                    break;
                case 2:

                    TabContainer.AddPage(index, new ModuleB.MainForm());
                    TabContainer.SelectPage(index);
                    break;
                case 3:

                    TabContainer.AddPage(index, new ModuleC.MainForm());

                    break;
                default:
                    break;
            }
            TabContainer.SelectPage(index);

        }



        private void Shell_Load(object sender, EventArgs e)
        {

            (this.TitleBarTextControl as CaptionBar).SelectFirst();


            this.toolStripStatusLabelUserInfo.Text
                = $"{IdentityContext.Current.UserName}[{IdentityContext.Current.UserType}]";

            Hub.Default.Subscribe<string>(this, message =>
            {

                //if (this.toolStripStatusLabelMsg.)
                //{
                //    //Action<bool> actionDelegate = (x) => { this.btnSyncData.Enabled = x; };

                //    //this.btnSyncData.Invoke(actionDelegate, !notify.DisableRemoteOpt);
                //}
                //else
                //{
                //    //this.btnSyncData.Enabled = !notify.DisableRemoteOpt;
                //}

                this.toolStripStatusLabelMsg.Text = message;
                timerClearMessage.Enabled = true;
               
            });


        }

        private void timerClearMessage_Tick(object sender, EventArgs e)
        {
            this.toolStripStatusLabelMsg.Text = string.Empty;
            timerClearMessage.Enabled = false;

        }
    }
}

